package com.common.app.data.repository

import com.common.app.data.api.ApiConstant.getBaseUrl
import com.common.app.data.bean.home.AllScoringModel
import com.common.app.data.bean.home.HomeDetailBean
import com.common.app.data.bean.home.HomeMainCardModel
import com.common.app.data.bean.home.ScoringFactorsModel
import com.common.base.data.CommonBean
import com.common.base.data.ListCommon
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import rxhttp.toAwait
import rxhttp.wrapper.param.RxHttp

/**
 * 作者：sosou
 * <p>
 * 版本：1.0
 * <p>
 * 创建日期：2022/8/20
 * <p>
 * 描述：
 * <p>
 * 修订历史：
 */
object HomeApi {

    //获取首页通知
    private val HONE_MAIN_AI_NOTIFICATIONS = getBaseUrl() + "api/v1/ocell-ring/notifications/home"
    //上传健康数据
    val UP_HEALTH_DATA = getBaseUrl() + "api/v1/smart-ring/vital-sign/upload"
    //获取睡眠评分详情
    val GET_SLEEP_SCORING_FACTORS = getBaseUrl() + "api/v1/ocell-ring/score/sleep-detail"
    //获取体征评分详情
    val GET_SIGNS_SCORING_FACTORS = getBaseUrl() + "api/v1/ocell-ring/score/vital-signs"
    //获取压力评分详情
    val GET_STRESS_SCORING_FACTORS = getBaseUrl() + "api/v1/ocell-ring/score/stress"
    //获取活动评分详情
    val GET_ACTIVITY_SCORING_FACTORS = getBaseUrl() + "api/v1/ocell-ring/score/activity"
    //获取四个评分数据
    val GET_ACTIVITY_ALL_SCORING_FACTORS = getBaseUrl() + "api/v1/ocell-ring/score/ai-analysis"
    //标记同步状态为完成
    val GET_ACTIVITY_ALL_SYS_FINISHED = getBaseUrl() + "api/v1/smart-ring/vital-sign/sync-finished"

    suspend fun getHomeAiNotifDetail() =
        withContext(Dispatchers.IO) {
            RxHttp.get(HONE_MAIN_AI_NOTIFICATIONS)
                .toAwait<ListCommon<HomeMainCardModel>>()
                .await()
        }

    suspend fun getSleepScoringFactors(urlType:Int,date :String) =
        withContext(Dispatchers.IO) {
            RxHttp.postJson(when(urlType){
                1->GET_SLEEP_SCORING_FACTORS
                2->GET_ACTIVITY_SCORING_FACTORS
                3->GET_SIGNS_SCORING_FACTORS
                else->GET_STRESS_SCORING_FACTORS
            })
                .add("date", date)
                .toAwait<CommonBean<ScoringFactorsModel>>()
                .await()
        }


    suspend fun getAllScoringFactors(date :String) =
        withContext(Dispatchers.IO) {
            RxHttp.postJson(GET_ACTIVITY_ALL_SCORING_FACTORS)
                .add("date", date)
                .toAwait<CommonBean<AllScoringModel>>()
                .await()
        }

}